home *** CD-ROM | disk | FTP | other *** search
/ The Arsenal Files 8 / The Arsenal Files Collection #8 (Arsenal Computer) (1996).ISO / g_quake / ultqsrc.zip / BUTTONS.QC < prev    next >
Text File  |  1996-09-20  |  3KB  |  144 lines

  1. // button and multiple button
  2.  
  3. void() button_wait;
  4. void() button_return;
  5.  
  6. void() button_wait =
  7. {
  8.     self.state = STATE_TOP;
  9.     self.nextthink = self.ltime + self.wait;
  10.     self.think = button_return;
  11.     activator = self.enemy;
  12.     SUB_UseTargets();
  13.     self.frame = 1;            // use alternate textures
  14. };
  15.  
  16. void() button_done =
  17. {
  18.     self.state = STATE_BOTTOM;
  19. };
  20.  
  21. void() button_return =
  22. {
  23.     self.state = STATE_DOWN;
  24.     SUB_CalcMove (self.pos1, self.speed, button_done);
  25.     self.frame = 0;            // use normal textures
  26.     if (self.health)
  27.         self.takedamage = DAMAGE_YES;    // can be shot again
  28. };
  29.  
  30.  
  31. void() button_blocked =
  32. {    // do nothing, just don't ome all the way back out
  33. };
  34.  
  35.  
  36. void() button_fire =
  37. {
  38.     if (self.state == STATE_UP || self.state == STATE_TOP)
  39.         return;
  40.  
  41.     sound (self, CHAN_VOICE, self.noise, 1, ATTN_NORM);
  42.  
  43.     self.state = STATE_UP;
  44.     SUB_CalcMove (self.pos2, self.speed, button_wait);
  45. };
  46.  
  47.  
  48. void() button_use =
  49. {
  50.     self.enemy = activator;
  51.     button_fire ();
  52. };
  53.  
  54. void() button_touch =
  55. {
  56.       if(other.classname!="player")  
  57.               if(other.skin!=1)
  58.                       if(other.classname!="corpse"&&other.classname!="throwaxe")
  59.                             return;
  60.       self.enemy = other;
  61.       button_fire ();
  62. };
  63.  
  64. void() button_killed =
  65. {
  66.     self.enemy = damage_attacker;
  67.     self.health = self.max_health;
  68.     self.takedamage = DAMAGE_NO;    // wil be reset upon return
  69.     button_fire ();
  70. };
  71.  
  72.  
  73. /*QUAKED func_button (0 .5 .8) ?
  74. When a button is touched, it moves some distance in the direction of it's angle, triggers all of it's targets, waits some time, then returns to it's original position where it can be triggered again.
  75.  
  76. "angle"        determines the opening direction
  77. "target"    all entities with a matching targetname will be used
  78. "speed"        override the default 40 speed
  79. "wait"        override the default 1 second wait (-1 = never return)
  80. "lip"        override the default 4 pixel lip remaining at end of move
  81. "health"    if set, the button must be killed instead of touched
  82. "sounds"
  83. 0) steam metal
  84. 1) wooden clunk
  85. 2) metallic click
  86. 3) in-out
  87. */
  88. void() func_button =
  89. {
  90. local float        gtemp, ftemp;
  91.  
  92.     if (self.sounds == 0)
  93.     {
  94.         precache_sound ("buttons/airbut1.wav");
  95.         self.noise = "buttons/airbut1.wav";
  96.     }
  97.     if (self.sounds == 1)
  98.     {
  99.         precache_sound ("buttons/switch21.wav");
  100.         self.noise = "buttons/switch21.wav";
  101.     }
  102.     if (self.sounds == 2)
  103.     {
  104.         precache_sound ("buttons/switch02.wav");
  105.         self.noise = "buttons/switch02.wav";
  106.     }
  107.     if (self.sounds == 3)
  108.     {
  109.         precache_sound ("buttons/switch04.wav");
  110.         self.noise = "buttons/switch04.wav";
  111.     }
  112.     
  113.     SetMovedir ();
  114.  
  115.     self.movetype = MOVETYPE_PUSH;
  116.     self.solid = SOLID_BSP;
  117.     setmodel (self, self.model);
  118.  
  119.     self.blocked = button_blocked;
  120.     self.use = button_use;
  121.  
  122.     if (self.health)
  123.     {
  124.         self.max_health = self.health;
  125.         self.th_die = button_killed;
  126.         self.takedamage = DAMAGE_YES;
  127.     }
  128.     else
  129.         self.touch = button_touch;
  130.  
  131.     if (!self.speed)
  132.         self.speed = 40;
  133.     if (!self.wait)
  134.         self.wait = 1;
  135.     if (!self.lip)
  136.         self.lip = 4;
  137.  
  138.     self.state = STATE_BOTTOM;
  139.  
  140.     self.pos1 = self.origin;
  141.     self.pos2 = self.pos1 + self.movedir*(fabs(self.movedir*self.size) - self.lip);
  142. };
  143.  
  144.